from typing import List, Optional
from attrs import define, field
from .models import UsersGetAPIResponseItem, UsersPostAPIResponse, UsersGetAPIResponse
from aomaker.core.api_object import BaseAPIObject
from aomaker.core.router import router

__ALL__ = ["UsersGetAPI", "UsersPostAPI", "UsersGetAPI_1"]


@define(kw_only=True)
@router.get("/users")
class UsersGetAPI(BaseAPIObject[UsersGetAPIResponseItem]):
    """返回所有用户的列表"""

    response: Optional[UsersGetAPIResponseItem] = field(default=UsersGetAPIResponseItem)
    endpoint_id: Optional[str] = field(default="/users_get")


@define(kw_only=True)
@router.post("/users")
class UsersPostAPI(BaseAPIObject[UsersPostAPIResponse]):
    """根据提供的信息创建一个新用户"""

    @define
    class RequestBodyModel:
        name: str = field()
        email: str = field()
        age: Optional[int] = field(default=None)

    request_body: RequestBodyModel

    response: Optional[UsersPostAPIResponse] = field(default=UsersPostAPIResponse)
    endpoint_id: Optional[str] = field(default="/users_post")


@define(kw_only=True)
@router.get("/users/{id}")
class UsersGetAPI_1(BaseAPIObject[UsersGetAPIResponse]):
    """根据用户ID返回用户详细信息"""

    @define
    class PathParams:
        id: int = field(metadata={"description": "用户ID"})

    path_params: PathParams
    response: Optional[UsersGetAPIResponse] = field(default=UsersGetAPIResponse)
    endpoint_id: Optional[str] = field(default="/users/{id}_get")
